package ControllerLayer;

import ModelLayer.*;
import DBLayer.*;
import java.util.ArrayList;
/**
 *
 * @author Gruppe 2
 */
public class SalesOrderController {
    private DbSalesOrder DBSO = new DbSalesOrder();
    private static SalesOrderController instance;
    private ProductController productController = ProductController.getInstance();


    private SalesOrderController()
    {}

    public static synchronized SalesOrderController getInstance()
    {
        if (instance == null)
        {
            instance = new SalesOrderController();
        }
        return instance;
    }

    public boolean deleteOrder(int saleOrderID)
    {
        return false;
    }

    public SalesOrder getOrder(int orderID)
    {
        return DBSO.searchSalesOrderID(orderID);
    }

    public void createOrder(SalesOrder order)
    {
        DBSO.insertSalesOrder(order);
    }
//
//    public boolean addItemToOrder(int barcode)
//    {
//    return addItemToOrder(ic.getItem(barcode));
//    }

    // Add item to order

    public void addItemToOrder(SalesOrder order, int productID) {
        int salesID = order.getSalesOrderID();
        if(DBSO.searchSalesOrderID(salesID) != null)
        {
        Product prod = productController.findProduct(productID,false);
        if(productID > 0) {
           
            SalesLineItem SLI = new SalesLineItem(1, prod);

            order.addSalesLine(SLI);
            }
    }
   }






}
